/*
* @Author: majingyu
* @Date:   2017-05-30 15:40:33
* @Last Modified by:   jingyu.ma
* @Last Modified time: 2017-08-07 21:59:27
*/
import Fetch from 'common/fetch';
import { getParams } from 'common/getParams';
//获取摸个订单的评论列表
const getNoticeListType = (type, data) => {
    let action = {
        type:type
    }
    if(type == GET_NOTICE_SUCCESS){
        action['data'] = data;
    }else if(type == GET_NOTICE_ERROR){
        action['e'] = data;
    }else if(type == GET_NOTICE_BIGIN){
        action['data'] = data;
    }
    return action;
}
const GET_NOTICE_BIGIN = 'GET_NOTICE_BIGIN';
const GET_NOTICE_SUCCESS = 'GET_NOTICE_SUCCESS';
const GET_NOTICE_ERROR = 'GET_NOTICE_ERROR';

export const getNoticeList = (params) => (dispatch, getState) => {
    dispatch(getNoticeListType(GET_NOTICE_BIGIN));
    let myHeaders = new Headers();
    let paramlist = getParams(params);
    myHeaders.append('Content-Type', 'application/json');
    return Fetch('/wx/notice/list?'+paramlist ).then(res=>res.json()).then((data)=>{
        if(data.status == 200){
            dispatch(getNoticeListType(GET_NOTICE_SUCCESS, data.data));
        }else{
            message.error(data.err)
            dispatch(getNoticeListType(GET_NOTICE_ERROR,data.error));
        }
    }).catch(e=>{
        dispatch(getNoticeListType(GET_NOTICE_ERROR,e));
    })
}